<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="div">
        <p></p>
        <p></p>
        <p></p>
    </div>
    <script>
        const divs = document.getElementsByTagName('div')
        const hs = document.getElementById('div')

        /**
         * NodeList就是基于DOM文档的实时查询
        */
        // 这是个无限循环
        // for (let i=0; i<divs.length; i++) {
        //     let div = document.createElement("div")
        //     document.body.appendChild(div)
        // }

        // 防止无限循环: 初始化一个len, 保存最初的长度
        for (let i=0, len = divs.length; i<len; i++) {
            let div = document.createElement("div")
            document.body.appendChild(div)
            console.log(div)
        }
    </script>
</body>
</html>